package com.gzq.service.serviceImpl;

import com.gzq.entity.User;
import com.gzq.repository.UserRepository;
import com.gzq.service.UserService;
import com.mysql.cj.Session;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @description:
 * @author: duzi55
 * @date: 2019-07-01 09:03
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserRepository userRepository;
    @Override
    public boolean login(User user, HttpServletRequest request) {
        boolean flag=false;
        User u=userRepository.findUserByNameAndPassword(user.getName(),user.getPassword());
        if(u!=null){
            request.getSession().setAttribute("user",u);
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean regist(User user) {

        return userRepository.save(user)!=null;
    }

    @Override
    public boolean findByName(String name) {
       boolean flag=false;
       if(userRepository.findByName(name)!=null){
           flag=true;
       }
       return flag;
    }
}
